<?php

include(dirname(__FILE__).'/../../bootstrap/functional.php');

$browser = new CheckTestFunctional(new sfBrowser(), $t = new lime_test(12));

$browser->
  loadData()->
  info('The tags module is secured')->
  get('/tags')->
  with('response')->
    begin()->
    isStatusCode(401)->
  end()->
  signin()->
  get('/tags')->

  info('1 - Creation')->
  click('New')->
  info('  1.1 - The Name is required')->
  click('Save')->
  with('form')->begin()->
    hasErrors(1)->
    isError('name', 'required')->
  end()->
  click(
    'Save',
    array(
      'tag' => array(
        'name' => 'performance',
      )
    )
  )->
  get('/')->
  with('response')->checkElement('.tagList li:last', 'performance')->
  get('/tags')->

  info('2 - Order the  Todo display')->

  info('  2.1 - Up')->
  get('/')->
  with('response')->checkElement('.tagList li:nth-child(2)', 'high')->
  get('/tags')->
  click('Promote', array(), array('position' => 2, 'method' => 'put', '_with_csrf' => true))->
  with('response')->isRedirected()->followRedirect()->
  get('/')->
  with('response')->checkElement('.tagList li:nth-child(2)', 'design')->
  get('/tags')->


  info('  2.1 - Down')->
  get('/')->
  with('response')->checkElement('.tagList li:nth-child(2)', 'design')->
  get('/tags')->
  click('Demote', array(), array('position' => 1, 'method' => 'put', '_with_csrf' => true))->
  with('response')->isRedirected()->followRedirect()->
  get('/')->
  with('response')->checkElement('.tagList li:nth-child(2)', 'high')->
  get('/tags')
  ;